package svc

import (
	"charging_pile/devices/internal/config"
	"charging_pile/devices/types"
	"charging_pile/models"
	"fmt"

	"github.com/zeromicro/go-zero/core/netx"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config     config.Config
	LocalTopic string
	Modes      Modes
	Mq         types.Rpc2Mq
	// Cache      redis.Client
}

type Modes struct {
	ChargePile    models.ChargeingPileModel
	ChargePileDev models.ChargeingPileDevModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlconn := sqlx.NewMysql(c.DB.DataSource)
	return &ServiceContext{
		Config:     c,
		LocalTopic: netx.InternalIp() + fmt.Sprintf(":%d", c.Port),
		Modes: Modes{
			ChargePile:    models.NewChargeingPileModel(sqlconn, c.Cache),
			ChargePileDev: models.NewChargeingPileDevModel(sqlconn, c.Cache),
		},
	}
}
